// 统计分析相关的getters
export default {
  // 获取下载统计数据
  downloadStats: state => state.downloadStats,
  
  // 获取热门包数据
  popularPackages: state => state.popularPackages,
  
  // 获取趋势数据
  trendData: state => state.trendData,
  
  // 获取加载状态
  loading: state => state.loading,
  
  // 获取错误信息
  error: state => state.error,
  
  // 获取过滤器
  filters: state => state.filters,
  
  // 检查是否有下载统计数据
  hasDownloadStats: state => state.downloadStats.length > 0,
  
  // 检查是否有热门包数据
  hasPopularPackages: state => state.popularPackages.length > 0,
  
  // 检查是否有趋势数据
  hasTrendData: state => state.trendData.length > 0,
  
  // 获取总下载量
  totalDownloads: state => {
    return state.downloadStats.reduce((total, stat) => {
      return total + (stat.downloads || 0)
    }, 0)
  },
  
  // 获取平均下载量
  averageDownloads: state => {
    if (state.downloadStats.length === 0) return 0
    return Math.round(state.totalDownloads / state.downloadStats.length)
  },
  
  // 获取下载量最高的日期
  peakDownloadDate: state => {
    if (state.downloadStats.length === 0) return null
    return state.downloadStats.reduce((max, stat) => {
      return (stat.downloads || 0) > (max.downloads || 0) ? stat : max
    })
  },
  
  // 获取热门包数量
  popularPackageCount: state => state.popularPackages.length,
  
  // 获取下载统计数据的标签和值（用于图表）
  chartData: state => ({
    labels: state.downloadStats.map(stat => stat.date),
    values: state.downloadStats.map(stat => stat.downloads || 0)
  }),
  
  // 获取热门包的名称和下载量（用于图表）
  popularChartData: state => ({
    labels: state.popularPackages.map(pkg => pkg.name),
    values: state.popularPackages.map(pkg => pkg.downloads || 0)
  })
}